/**
 * 
 */
package com.mc.huaweicloud;

import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.ocr.v1.OcrClient;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeSmartDocumentRecognizerRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeSmartDocumentRecognizerResponse;
import com.huaweicloud.sdk.ocr.v1.model.SmartDocumentRecognizerRequestBody;
import com.huaweicloud.sdk.ocr.v1.region.OcrRegion;
import com.mc.file.Base64Util;

/**
 * @author w.weizhen
 *
 */
public class RecognizeSmartDocumentRecognizerSolution {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String base64 = Base64Util.encryptToBase64("D:\\hynetic\\file\\ocr_smart_document_recognizer_01.jpg");
		base64.substring(base64.indexOf(",") + 1).replaceAll("\r\n", "").replaceAll("\n", "");
		
		
		String ak = "FNV2AAKWAJE7XJQCURKQ";
        String sk = "8AD5Jz7jBZD0Uxbrq3wmEz7SK1E5aZJ6oa8f3R3O";

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        OcrClient client = OcrClient.newBuilder()
                .withCredential(auth)
                .withRegion(OcrRegion.valueOf("cn-north-4"))
                .build();
        RecognizeSmartDocumentRecognizerRequest request = new RecognizeSmartDocumentRecognizerRequest();
        SmartDocumentRecognizerRequestBody body = new SmartDocumentRecognizerRequestBody();
        body.withData(base64);
        request.withBody(body);
        try {
            RecognizeSmartDocumentRecognizerResponse response = client.recognizeSmartDocumentRecognizer(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
	}

}